import axios from '@/utils/request.js'
import store from '@/store'
/**
 * @returns ID
 * 时间戳
 */
export const getArtilceList = (channelId, timestamp) => axios({
  url: '/v1_0/articles',
  params: {
    channel_id: channelId,
    timestamp
  }
})

/**
 * 对文章不喜欢
 *
 * @export
 * @param {*} target 不喜欢的文章id
 * @return {*}
 */
export const articleDisLike = (target) => axios({
  method: 'POST',
  url: '/v1_0/article/dislikes',
  headers: {
    Authorization: 'Bearer ' + store.state.user.token.token
  },
  data: {
    target
  }
})

/**
 * @target {*} target 文章ID
 * @type {*} type     举报类型
 */
export const articleReport = (target, type) => axios({
  method: 'POST',
  url: '/v1_0/article/reports',
  headers: {
    Authorization: 'Bearer ' + store.state.user.token.token
  },
  data: {
    target,
    type
  }
})

/**
 * 获取新闻详情
 * @param {*} target Id
 */
export const getArtilceDetail = (target) => axios({
  url: '/v1_0/articles/' + target
})

/**
 * 取消关注作者
 * @param {*} target 关注的用户的id
 */
export const unFollowUser = (target) => {
  return axios({
    method: 'DELETE',
    url: '/v1_0/user/followings/' + target
  })
}

export const followUser = (target) => axios({
  method: 'POST',
  url: '/v1_0/user/followings',
  headers: {
    Authorization: 'Bearer ' + store.state.user.token.token
  },
  data: {
    target
  }
})

/**
 * 取消点赞
 * @param {*} id 文章编号
 */
export const deleteLike = id => {
  return axios({
    method: 'delete',
    url: '/v1_0/article/likings/' + id,
    headers: {
      Authorization: 'Bearer ' + store.state.user.token.token
    }
  })
}

/**
* 添加点赞
* @param {*} id 文章编号
*/
export const addLike = id => {
  return axios({
    method: 'post',
    url: '/v1_0/article/likings',
    headers: {
      Authorization: 'Bearer ' + store.state.user.token.token
    },
    data: {
      target: id
    }
  })
}

/**
* 取消不喜欢
* @param {*} id 文章编号
*/
export const deleteDisLike = id => {
  return axios({
    method: 'delete',
    url: '/v1_0/article/dislikes/' + id,
    headers: {
      Authorization: 'Bearer ' + store.state.user.token.token
    }
  })
}

/**
* 添加不喜欢
* @param {*} id 文章编号
*/
export const addDisLike = id => {
  return axios({
    method: 'post',
    url: '/v1_0/article/dislikes',
    headers: {
      Authorization: 'Bearer ' + store.state.user.token.token
    },
    data: {
      target: id
    }
  })
}

/**
 * 获取对文章的评论
 *
 * @export
 * @param {*} source 文章id
 * @param {*} offset 偏移量 获取第几页数据
 * @return {*}
 */
export const getArticleCommon = (source, offset) => axios({
  url: '/v1_0/comments',
  params: {
    type: 'a',
    source,
    offset,
    limit: 10
  }
})

/**
 * 对文章进行发表评论
 *
 * @export
 * @param {*} target 文章id
 * @param {*} content 评论内容
 * @return {*}
 */
export function addArticleCommon(target, content) {
  return axios({
    url: '/v1_0/comments',
    method: 'POST',
    headers: {
      Authorization: 'Bearer ' + store.state.user.token.token
    },
    data: {
      target,
      content
    }
  })
}

/**
 * 对评论进行点赞
 *
 * @export
 * @param {*} target 评论id
 * @return {*}
 */
export function likeCommon(target) {
  return axios({
    url: '/v1_0/comment/likings',
    method: 'post',
    headers: {
      Authorization: 'Bearer ' + store.state.user.token.token
    },
    data: {
      target
    }
  })
}

/**
 * 对评论进行取消点赞
 *
 * @export
 * @param {*} target 评论id
 * @return {*}
 */
export function unLikeCommon(target) {
  return axios({
    url: '/v1_0/comment/likings/' + target,
    method: 'DELETE',
    headers: {
      Authorization: 'Bearer ' + store.state.user.token.token
    }
  })
}

/**
 * 获取评论回复的评论
 *
 * @export
 * @param {*} source 评论id
 * @param {*} offset 偏移量 获取第几页数据
 * @return {*}
 */
export function getCommonToCommon(source, offset) {
  return axios({
    url: '/v1_0/comments',
    headers: {
      Authorization: 'Bearer ' + store.state.user.token.token
    },
    params: {
      type: 'c',
      source,
      offset,
      limit: 10
    }
  })
}

/**
 * 对评论进行发表评论
 *
 * @export
 * @param {*} artId 文章id
 * @param {*} target 评论id
 * @param {*} content 评论内容
 * @return {*}
 */
export const addCommonToCommon = (artId, target, content) => axios({
  url: '/v1_0/comments',
  method: 'post',
  headers: {
    Authorization: 'Bearer ' + store.state.user.token.token
  },
  data: {
    art_id: artId,
    target,
    content
  }
})
